package com.itheima.day07.test03;

import java.util.Scanner;

//1. 定义正方形类
class Square{
    //属性边长（side）
    private double side;

    //获取矩形周长(perimeter) : 正方形的周长 = 边长的四倍
    public double perimeter(){
        return this.getSide() * 4;
    }

    //面积（area）
    public double area(){
        return this.side * side;
    }

    public Square() {
    }

    public Square(double side) {
        this.side = side;
    }

    public double getSide() {
        return side;
    }

    public void setSide(double side) {
        this.side = side;
    }
}

//2. 定义长方形类
class Rectangle{
    private double width;
    private double height;

    //求周长
    public double perimeter(){
        return (width + height) * 2;
    }
    //求面积
    public double area(){
        return width * height;
    }

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    public Rectangle() {
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }
}

//3. 定义圆形类
class Round{
    //半径
    private double r;
    //圆周率
    private double π = 3.14;   //魔法值

    //求周长
    public double perimeter(){
        return 2*π*r;
    }
    //求面积
    public double area(){
        return π * r * r;
    }

    public Round() {
    }

    public Round(double r) {
        this.r = r;
    }

    public double getR() {
        return r;
    }

    public void setR(double r) {
        this.r = r;
    }
}

public class Test03 {
    public static void main(String[] args) {
        //1. 展示功能菜单
        System.out.println("请选择您要计算的图形:");
        System.out.println("0: 正方形  1: 长方形  2: 圆形");
        Scanner sc = new Scanner(System.in);
        int option = sc.nextInt();
        //2. 根据用户的选项进行对应图形的操作
        switch (option){
            case 0:
                SquareOption();
                break;
            case 1:
                RectangleOption();
                break;
            case 2:
                RoundOption();
                break;
            default:
                System.out.println("您的输入有误,请重试!");
                break;
        }

    }

    //正方形处理逻辑
    public static void SquareOption() {
        System.out.println("请输入正方形的边长:");
        Scanner sc = new Scanner(System.in);
        double side = sc.nextDouble();

        //根据边长封装正方形对象
        Square sq = new Square(side);

        //通过对象调方法获取对应的周长和面积
        System.out.println("正方形的周长是:"+ sq.perimeter());
        System.out.println("正方形的面积是:"+ sq.area());
    }

    //长方形处理逻辑
    public static void RectangleOption() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入长方形的宽:");
        double width = sc.nextDouble();
        System.out.println("请输入长方形的高:");
        double height = sc.nextDouble();

        //根据宽和高封装长方形对象
        Rectangle rt = new Rectangle(width,height);

        //通过对象调方法获取对应的周长和面积
        System.out.println("长方形的周长是:"+ rt.perimeter());
        System.out.println("长方形的面积是:"+ rt.area());
    }

    //圆形处理逻辑
    public static void RoundOption() {
        System.out.println("请输入圆形的半径:");
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();

        //根据边长封装圆形对象
        Round round = new Round(r);

        //通过对象调方法获取对应的周长和面积
        System.out.println("圆形的周长是:"+ round.perimeter());
        System.out.println("圆形的面积是:"+ round.area());
    }
}
